/*
-----------------------------------------------------------------------------
This source file is part of Labor3D
(Labor 3D Graphics Engine)

Copyright (c) 2009-2020 Rock Mao
* creator : Rock Mao
* created : 2009-5-4   14:52
* filename: LaborDynLibMgr.cpp
-----------------------------------------------------------------------------
*/

#include "Plugin\LaborDynLibMgr.h"
#include "Plugin\LaborDynLib.h"
NAMESPACE_LABOR3D_BEGIN

//-----------------------------------------------------------------------
template<> CLDynLibMgr* CLSingleton<CLDynLibMgr>::ms_Singleton = 0;

//---------------------------------------------------------------------
CLDynLibMgr::CLDynLibMgr()
{

}

//---------------------------------------------------------------------
CLDynLibMgr::~CLDynLibMgr()
{

}

//-----------------------------------------------------------------------
CLDynLib* CLDynLibMgr::load( const CLString& filename)
{
	DynLibList::iterator i = m_LibList.find(filename);
	if (i != m_LibList.end())
	{
		return i->second;
	}
	else
	{
		CLDynLib* pLib = new CLDynLib(filename);
		pLib->load();        
		m_LibList[filename] = pLib;
		
		return pLib;
	}
}

//-----------------------------------------------------------------------
void CLDynLibMgr::unload(CLDynLib* lib)
{
	DynLibList::iterator i = m_LibList.find(lib->getName());
	if (i != m_LibList.end())
	{
		m_LibList.erase(i);
	}
	lib->unload();
	SafeDelete(lib);
}

NAMESPACE_LABOR3D_END